package com.cw.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.entity.LJysqdxx;
import com.cw.entity.LJytmxx;
import com.cw.mapper3.LJysqdxxMapper;
import com.cw.service.ILJysqdxxService;
import com.cw.service.ILJytmxxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 检验 服务实现类
 * </p>
 *
 * @author ly
 * @since 2021-08-16
 */
@Service
public class LJysqdxxServiceImpl extends ServiceImpl<LJysqdxxMapper, LJysqdxx> implements ILJysqdxxService {
    
    @Autowired
    private LJysqdxxMapper lJysqdxxMapper;


    @Autowired
    private ILJytmxxService ilJytmxxService;

    /**
     * 根据主键集合查询检验数据
     * @param patientNo 处方号
     * @return java.util.List<com.cw.entity.LJysqdxx>
     * @author ly
     * @since 2021-08-20
     */
    @Override
    public List<LJysqdxx> getLJysqdxxsByDorctrequestno(String patientNo) {
        LambdaQueryWrapper<LJysqdxx> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(LJysqdxx::getPatientno, patientNo);
        // 可以用但对象接收
        List<LJysqdxx> list = list(lambdaQueryWrapper);
        if (CollectionUtil.isEmpty(list)) { return new ArrayList<>(); }
        for (LJysqdxx lJysqdxx : list) {
            String doctrequestno = lJysqdxx.getDoctrequestno();
            LambdaQueryWrapper<LJytmxx> lJysqdxxXmmxLambdaQueryWrapper = new LambdaQueryWrapper<>();
            lJysqdxxXmmxLambdaQueryWrapper.select(LJytmxx::getExaminaim,LJytmxx::getExaminaimcode,LJytmxx::getDoctrequestno,
                                                  LJytmxx::getReceivetime,LJytmxx::getExecutetime,
                                                  LJytmxx::getChecktime,LJytmxx::getSampleno);
            lJysqdxxXmmxLambdaQueryWrapper.eq(LJytmxx::getDoctrequestno, doctrequestno);
            lJysqdxx.setLJysqdxxXmmxList(ilJytmxxService.list(lJysqdxxXmmxLambdaQueryWrapper));
        }
        return list;
    }
}
